﻿using Architecture.Domian.DTO;
using Architecture.Domian.Entity;
using AutoMapper;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Architecture.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class StudentController : ControllerBase
    {
        private readonly IMapper _mapper;

        public StudentController(IMapper mapper)
        {
            _mapper = mapper;
        }

        [HttpGet]
        public async Task<StudentDTO> Get()
        {

            List<Student> stuList = new List<Student>()
            {
                new Student()
                {
                    Id = 1,
                    Name = "李四",
                    Age = 18,
                    Genter = "女",
                    Pwd = "123"
                },
                new Student()
                {
                    Id = 2,
                    Name = "王五",
                    Age = 23,
                    Genter = "男",
                    Pwd = "1234"
                },
                new Student()
                {
                    Id = 3,
                    Name = "赵六",
                    Age = 45,
                    Genter = "女",
                    Pwd = "12345"
                },
            };


            List<StudentDTO> dtoList  = _mapper.Map<List<StudentDTO>>(stuList);

            StudentDTO Studto = new()
            {
                StuDTOId = 1,
                Name = "李四",
                Age = 18,
                Genter = "女"
            };

            Student stu = new()
            {
                Id = 1,
                Name = "张三",
                Age = 12,
                Genter = "男",
                Pwd = "123"
            };

            Student model = _mapper.Map<StudentDTO, Student>(Studto, stu);

            StudentDTO dto = _mapper.Map<StudentDTO>(stu);

            return dto;
        }
    }
}
